DIFF
version 1.2
7-2-90
What it is . . .
      DIFF is a program that will check to see if any files in a specified
directory tree have changed since the last time the utility was run.
Why use it . . .
      If you want to find out what files have changed recently in a certain
directory (or directory tree), DIFF will come in handy.  It is especially
helpful on a network where many people may have access to certain files that
you need to keep track of.  There are some useful examples of DIFF toward the
end of this document.
How it does it . . .
      DIFF creates either one or two files for its own use depending upon how
you wish to use it.
      The first is a Benchmark file containing the date and time of the last
time the utility was run.  It also contains a list of all of the files in the
directory along with their dates, times, and sizes as they were at the time
the Benchmark file was created.
      Here is a portion of a Benchmark file:
      ;DIFF Benchmark created   7-2-1990 at 15:10
      ;File sizes, dates, and times in directory:
      ;
      >C:\*.*
      IO      .SYS      33337  12-19-1988   0:00:02
      MSDOS   .SYS      37376  04-19-1989   8:38:32
      DOUG'S                0  04-25-1990  14:33:30
      BIZLINK          
   06-06-1990   9:22:18
      DOS                 04-25-1990  14:02:46
      WP51                04-25-1990  14:25:52
      AUTOEXEC.BAT       1668  07-02-1990  11:10:36
      COMMAND .COM      37557  12-19-1988   0:00:02
      CONFIG  .SYS        370  07-02-1990  13:58:12
      ;
      >C:\BIZLINK\*.*
      DOUG                06-06-1990   9:24:34
      ATTACH  .WPM       3739  05-24-1990   0:00:00
      ATTCHCTL.CMD      18258  06-18-1990   0:00:00
      BIZLINK .CMD      43434  06-18-1990   0:00:00
      BIZLINK .EXE      48556  06-06-1990   0:00:00
      ;
      Notice that DIFF picks up Hidden, System, and Read Only files (IO.SYS
and MSDOS.SYS).  The file 'DOUGS' is acutally not a file, but the Volumne
label on drive C:.  You'll also notice that DIFF considers seconds on a file's
time stamp to be significant (DOS doesn't display them, but they are there). 
Even if someone resets the clock to the date and time that DOS display for a
particular file and then modifies that file, DIFF will likely report a
difference due to the seconds.
      The second file (if you tell DIFF to create it) is a Difference file
containing a list of all of the files that have been changed (according to
date, time, and filesize) since the Benchmark file was created.
      Here is a portion of a Difference File:
      ;
      ;DIFF Difference file created  7-2-1990 at 15:19
      ;Benchmark file used: 'DIFF.LOG'.
      ;
      >C:\LIBRARY\*.*
      DM_}ED  .SET        332  07-02-1990  15:12:22  Time
      ;    1 - Difference(s)
      ;
      >C:\TC\WORK\DIFF\*.*
      DIFF    .EXE     154363  07-02-1990  15:19:06 Size Time
      DIFF    .LOG     155746  07-02-1990  15:10:52 Size Date Time
      DIFF    .OBJ      19380  07-02-1990  15:19:02 Size Time
      DIFF    .DIF        766  07-02-1990  15:15:36 Added
      DIFF    .PRJ      32643  07-02-1990  15:19:06 Size Time
      DIFF    .CPP      26598  07-02-1990  15:18:46 Size Time
      DIFF    .BAK      26615  07-02-1990  15:14:38 Deleted
      ;    7 - Difference(s)
      ;
      ;  113 - total Directories processed
      ; 3255 - total Items processed
      ;    8 - total Difference(s)
      Note that DIFF will find HIDDEN directories that are newly added or
deleted but will not check any files inside hidden directories for differenc-
es.  See the note about 'A Little Trick' below.
      When DIFF checks your files, it reads the Benchmark file and compares it
against the current contents of the directories that you told it to check.  If
it finds files that have been changed, it writes a list of them to a Differ-
ence file (and/or optionally, to the screen).
Running it . . .
      DIFF has many options that tell it exactly what you want it to do.  Each
time you run it, DIFF will essentially do one of two things, create a
Benchmark file, or check a directory against an existing Benchmark file.
Usage:  DIFF option [option...] [path\filespec]
     þ      When running DIFF, you can have DIFF.EXE anywhere that DOS can
            find it (in the current directory or in your path).
     þ      You may specify any of DIFF's options in any order whatsoever.
     þ      If you specify two conflicting options (like /D and /N) the last
            one encountered will take precedence over the prior one.
     þ      You must separate each option with a space.  If you do not, DIFF
            will not be able to distinguish between them.  For example, DIFF
            will interpret 'DIFF /M/O' incorrectly (DIFF will think you meant
            'DIFF /M-O'.
     þ      The dash '-' characters in certain parameters are necessary,
            without them, DIFF will get confused about what you intended it to
            do.  Actually, the dash could be any character (as long as there
            is something there DIFF doesn't care what is used).  You could say
            'DIFF /M/O' and DIFF would think you meant 'DIFF /M-O' and would
            create a Benchmark file named 'O' in the current directory.
     þ      If you do not specify any options, DIFF displays its help screen.
      Since there are so many different command line options, the following
section will explain each one in further detail.
The Finer Points
      This is part of DIFF's help screen.  It displays a quick summary of each
option.
Options
  /M-filename Make Benchmark file using 'filename'
  /C-filename Check directory using 'filename' as a Benchmark.
  /D-filename Write Difference file to 'filename.'
  /R-levels   Recursive operation.  Levels = the number of dir levels to scan.
  /S          Screen display on.  Echos Difference file to screen.
  /N          No Difference file.  (Implies /S)
  /U          Unchanged files displayed and/or written in Difference file.
  /O          Overwrite old Benchmark file with the newly created one.
  /A          Append to Benchmark or Difference file (depends on /M or /C).
  /H          Display this help screen.
  path        The 'path' to begin working in (MUST END WITH A BACKSLASH)!
  filespec    The filename mask (e.g. '*.*') to use in 'path.'
Examples
  DIFF /M /O  Make a Benchmark file of the current dir named DIFF.LOG
  DIFF /C     Check Benchmark DIFF.LOG against current directory
              and write differences to DIFF.DIF
/M-filename
      Make a Benchmark file using 'filename'.  If 'filename' is not specified,
the name DIFF.LOG is used.  This tells DIFF to create a Benchmark file named
DIFF.LOG in the current directory.  Optionally you can specify a full path and
filename to tell DIFF to create the Benchmark somewhere else.
/C-filename
      Check a directory (or directory tree) against 'filename.'  If 'filename'
is not specified, the name DIFF.LOG is used.  This tells DIFF to compare a
directory (or directory tree) against the files and directories listed in the
Benchmark file.  DIFF compares each file that it finds against the information
included in the Benchmark file, and if anything is different (size, date, or
time), it reports what has changed by writing it to a file or to the screen
(depending upon the /S and /N options).
/D-filename
      Create a Difference file named 'filename.'  If 'filename' is not
specified, the name DIFF.DIF is used.  This option is only needed if you wish
to use a different Difference file name.
      This option is only valid when used with the /C option.  
/R-levels
      Scan the directory tree recursively down to 'levels' levels deep.  If
'levels' is not specified, DIFF will scan all levels 'under' the starting
directory level.
      For example, if your directory tree looked like this:
      C:\
      ÃÄÄÄ UTIL
      ³    ÀÄÄÄ MISC
      ÀÄÄÄ WP51
           ÃÄÄÄ DOC
           ÀÄÄÄ GRAPHICS
    þ without /R þ would include only the root directory (C:\).
    þ /R-1 þ would include the directories C:\, C:\UTIL\, and C:\WP51\.
    þ /R þ would include all of the directories.
    þ /R-2 þ would do the same thing as /R in this case since the deepest
      directory is only 2 levels deep.
      You can also use /R to process only a specific branch of the directory
tree.  If you had specified:
      DIFF /M /R C:\WP51\
      DIFF would have processed the directories C:\WP51\, C:\WP51\DOC\, and
C:\WP51\GRAPHICS.
      Note:  Using this option on a large network drive can take quite a
while.  Since it may not look like it is doing anything, you may think your
machine has 'hung', but be patient, it does work.
/S
      Screen display.  If this option is specified, DIFF will echo all data to
the screen as well as to the Difference file (if one is being created).
      Pressing any key while DIFF is displaying changed file information on
the screen will either stop screen display (turn off the /S option), or abort
the program (if /N was specified).  This can be useful when you are running
DIFF with a batch file that uses the /S option but you don't need (or want) to
see all of the information on the screen.
      This option is only valid when used with the /C option.
/N
      No Difference file.  If this option is specified, DIFF will not create a
Difference file.
      This option automatically sets the /S option.
      This option is only valid when used with the /C option.
/U
      Include unchanged files.  If this option is specified, DIFF will include
unchanged files in the Difference file (or display).  Normally DIFF only
reports the files which have changed since the last Benchmark was created. 
This option will allow DIFF to display ALL files.
      This option is only valid when used with the /C option.
/O
      Overwrite Benchmark file.  If this option is specified, DIFF will
automatically overwrite an existing Benchmark file when creating a new
Benchmark.  The default is not to overwrite an existing file.
      This option is only valid when used with the /M option.
/A
      Append to Benchmark or Difference file.  If this option is specified,
DIFF will append all information that it produces to an existing Benchmark or
Difference file.  If the file does not exist, it will be created.  For
example, this option could be used when you want your Difference file to be a
revision history of each time that the files have (or have not) changed.
/H
      Help.  If this option is specified (anywhere) on the command line, DIFF
will display its help screen and then exit.
path
      The path to begin working on.  If included, the path MUST end with the
backslash character ('\').  If it does not end in a backslash character (e.g.
'C:\UTIL'), DIFF will use the intended directory name as a part of the
'filespec' parameter (see below).  In the example, instead of using
'C:\UTIL\*.*' (as intended) DIFF would use 'C:\UTIL.*' and would only check
the files named 'UTIL.*' in the root directory of drive C:.  
filespec
      The filename mask to use when searching for files.  This can include the
wildcard characters '*' and '?.'  If a filename or an extension is not
supplied (e.g. "TEST" or ".DOC" or nothing at all), the wildcard '*' will be
supplied automatically and the examples would become "TEST.*", "*.DOC", and
"*.*" respectively.
Errorlevels returned to DOS
      When used with the /C option, DIFF will return an errorlevel to DOS (for
use in batch files) indicating how many differences it found when comparing
files.  If the number of differences exceeds 250, it will return an errorlevel
of 255 (the maximum allowed by DOS).  This was to allow for the following
error messages to be reported via errorlevel.
      DIFF will return the following error codes under the listed circumstanc-
es.
    251  þ  Couldn't open Benchmark file.
    252  þ  Couldn't open Difference file.
    253  þ  Help was requested on the command line.
    254  þ  DIFF couldn't find anything useful to do.  Most likely, /C or /M
            was not specified.
      The following segment of text is a batch file that controls what happens
when there are errors or certain numbers of differences.
      diff /c-c:\log\diff.Log /d-c:\log\diff.dif /r c:\
      if errorlevel 255 goto lots
      if errorlevel 251 goto error
      if errorlevel 11 goto some
      if errorlevel 1 goto few
      
      :none
      echo There were No Differences.
      goto end
      
      :lots
      echo There were Lots of differences (more than 250).
      goto end
      
      :some
      echo There were Some differences (between 11 and 250).
      goto end
      
      :few
      echo There were a Few differences (between 1 and 10).
      goto end
      
      :error
      echo There was an error running DIFF (don't know what kind).
      
      :end
      echo Done!
      Note the order in which errorlevels are checked.  When DOS sets an
errorlevel, all lower errorlevels become true.  In other words, if DOS sets
the errorlevel to 100, then 99, 98, and everything down to 0 is set as well. 
For this reason, you must check the highest errorlevels first, and work your
way down to the lower error levels.
      When used with the /M option, DIFF will return the following
errorlevels.
      0  þ  Successful in creating the Benchmark file.
      1  þ  Terminated because the Benchmark file existed and /O or /A was not
            specified.
    251  þ  Couldn't open Benchmark file.
    253  þ  Help was requested on the command line.
    254  þ  DIFF couldn't find anything useful to do.  Most likely, /C or /M
            was not specified.
A Little Trick
      If you use DIFF to check your entire Hard Drive, you will find that it
will always report that the Benchmark file, and sometimes the Difference file
have been changed since the last run.  In order to get around this, you can
create a hidden directory where DIFF does not check files for differences.  If
you store your Benchmark and your Difference files in a hidden directory, they
will not be checked for differences when scanning your entire drive.  You will
be able to see if someone has created or deleted a hidden directory, but not
if they have made changes to the files within that directory.
      To create a hidden directory requires a specialized utility.  Normal DOS
will not allow you to create a hidden directory.  I use DirMagic on my system,
although many others will work just as well.
Specifications
      DIFF:
    þ was written, compiled, and linked with Turbo C++ by Borland
    þ was packed with EXEPACK version 4.00 by Microsoft and TINYPROG by
            Tranzoa, Co.
    þ was developed under DOS 4.01
    þ has been tested with Novell Netware up through version 386 3.0
    þ will support up to 2500 files per directory (maximum due to memory
            limitations)
    þ will support up to 3000 directories on a single volume (hard disk)
    þ requires approximately 170K bytes of RAM to run
    þ was designed with command line or batch file operation in mind
    þ is free and I don't expect anyhing except enhancements or bug reports.
    þ will be updated if bugs are found or enhancement requests are received
            and implemented.
Examples
      Here are a few ways that I have found DIFF can be used.  If you think
your way of using DIFF could be widely used, let me know so I can document it
here.
Document Management System
      This is a very simple use of DIFF.  It allows many people to make
changes to a group of documents in a given directory and allows you to check
the directory periodically to see if any of the documents have been updated in
case they need to be printed, or otherwise processed.
      To make the Benchmark, be logged to the directory containing the
documents that you want to check and type the command:
      DIFF /M /O
      To check the Benchmark, be logged to the directory containing the
documents that you want to check and type the command:
      DIFF /C /S
      The results of these two steps will be a file named DIFF.DIF in the
directory where the documents reside as well as the display on the screen of
the documents that have been changed.
Crude Security System
      
      This is one way to make a Benchmark of, and later check, your entire
hard drive.  This is a sort of crude security system that doesn't stop anyone
from making changes to your system, but does tell you what has been changed.
      First, to make the Benchmark, you may be logged to any drive or any
directory you choose.  then type the command:
      DIFF /M-C:\DRIVEC.LOG /O /R C:\
      DIFF will create a Benchmark file named DRIVEC.LOG in the root directory
of drive C:.  If a file with that name already existed, DIFF will overwrite
it.  DIFF will start in the root directory of drive C: and will process all of
the directories on the entire drive logging all file to DRIVEC.LOG as it goes.
      Second, to check the entire hard drive against the Benchmark you may be
logged to any drive or directory on your system and type the command:
      DIFF /C-C:\DRIVEC.LOG C:\ /D-C:\DRIVEC.DIF /R
      DIFF will look for an file in the root directory of drive C: named
DRIVEC.LOG.  It will then use this file to compare all directories on drive C:
(starting at the root directory) and log any differences to DRIVEC.DIF in the
root directory of drive C:.  The final results of these two commands will be a
file named C:\DRIVEC.DIF which will contain a list of files that had changed
between the time you made the Benchmark and the time you checked it.
Enjoy!
      If you have any questions, enhancements or bug reports, please feel free
to contact me at:
      Doug McKay
      294 East Nineta Circle
      Orem, UT  84057-4703
      (801) 224-7288
         ----------------end-of-author's-documentation---------------
                         Software Library Information:
                    This disk copy provided as a service of
                           Public (software) Library
         We are not the authors of this program, nor are we associated
         with the author in any way other than as a distributor of the
         program in accordance with the author's terms of distribution.
         Please direct shareware payments and specific questions about
         this program to the author of the program, whose name appears
         elsewhere in  this documentation. If you have trouble getting
         in touch with the author,  we will do whatever we can to help
         you with your questions. All programs have been tested and do
         run.  To report problems,  please use the form that is in the
         file PROBLEM.DOC on many of our disks or in other written for-
         mat with screen printouts, if possible.  PsL cannot debug pro-
         programs over the telephone, though we can answer questions.
         Disks in the PsL are updated  monthly,  so if you did not get
         this disk directly from the PsL, you should be aware that the
         files in this set may no longer be the current versions. Also,
         if you got this disk from another vendor and are having prob-
         lems,  be aware that  some files may have become corrupted or
         lost by that vendor. Get a current, working disk from PsL.
         For a copy of the latest monthly software library newsletter
         and a list of the 2,000+ disks in the library, call or write
                           Public (software) Library
                               P.O.Box 35705 - F
                            Houston, TX 77235-5705
                                1-800-2424-PSL
                                 MC/Visa/AmEx
                          Outside of U.S. or in Texas
                          or for general information,
                              Call 1-713-524-6394
                          PsL also has an outstanding
                          catalog for the Macintosh.